﻿namespace NoIdeaIoc.Logger;
public class DefaultLoggerFactory : ILogFactory, IDisposable
{
    ILoggerProvider thisProvider;

    private LogLevel? _Level;
    /// <summary>日志等级，只输出大于等于该级别的日志，默认为最低的Debug</summary>
    public LogLevel MinLevel
    {
        get
        {
            if (_Level != null) return _Level.Value;
            return LogLevel.Information;
        }
        set { _Level = value; }
    }
    /// <summary>
    /// 添加日志提供者接口
    /// </summary>
    /// <param name="provider"></param>
    public void AddProvider(ILoggerProvider provider)
    {
        Interlocked.Exchange(ref thisProvider, provider);
    }
    /// <summary>
    /// 创建日志
    /// </summary>
    /// <param name="categoryName"></param>
    /// <returns></returns>
    public ILogger CreateLogger(string categoryName)
    {
        if (thisProvider != null) return thisProvider.CreateLogger(categoryName);
        return new ConsoleLog();
    }
    /// <summary>
    /// 根据事件源创建日志
    /// </summary>
    /// <returns></returns>
    public ILogger GetLog<T>()
    {
        return new ConsoleLog();
    }
    /// <summary>
    /// 根据事件源创建日志
    /// </summary>
    /// <returns></returns>
    public ILogger<T> GetLogger<T>()
    {
        return new ConsoleLog<T>();
    }
    public void Dispose()
    {
    }

    public ILogger GetLog(string eventSource)
    {
        return new ConsoleLog();
    }

    public bool IsEnabled(LogLevel logLevel)
    {
        return true;
    }
}
